from langchain_openai import ChatOpenAI
from langchain_core.prompts import  PromptTemplate
from langchain_core.output_parsers import StrOutputParser

#创建模型
mode = ChatOpenAI(model_name="qwen-plus",
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
    api_key="sk-4f1498f1c0314ba79ea2919bd7a02c4d",
    temperature=0.7
)

#创建prompt AIGC
prompt_template = PromptTemplate(
    template="请问{product}是谁",
    input_variables=["product"]
)
result = prompt_template.invoke({"product": "李云龙"})

#调用大模型
response = mode.invoke(result)

# print(response.content)

#创建输出解析器
out_parser = StrOutputParser()
answer = out_parser.invoke(response)
print(answer )